package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 频道信息表 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理API") // Swagger,knife4j
public class WmChannelController {

    @Autowired
    private IWmChannelService iWmChannelService;

    /**
     * 根据名称模糊查询分页列表
     * @param channelDto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "根据名称模糊查询分页列表", notes = "author:liJie")  // value指名称  notes 备注
    @ApiImplicitParam(name = "channelDto", value = "查询对象", required = true, dataType = "ChannelDto")
    public ResponseResult listByName(@RequestBody ChannelDto channelDto){
        log.info("[自媒体微服务======>分页查询频道接口，接收参数：{}]",channelDto.toString());
        return iWmChannelService.listByName(channelDto);
    }

    /**
     * 频道新增
     * @param wmChannel
     * @return
     */
    @PostMapping
    @ApiOperation(value = "频道新增", notes = "author:liJie")  // value指名称  notes 备注
    @ApiImplicitParam(name = "wmChannel", value = "新增频道对象", required = true, dataType = "WmChannel")
    public ResponseResult saveChannel(@RequestBody WmChannel wmChannel){
        log.info("[自媒体微服务======>新增频道接口，接收参数：{}]",wmChannel.toString());
        return iWmChannelService.saveChannel(wmChannel);
    }

    /**
     * 频道展示
     * @return
     */
    @GetMapping("channels")
    @ApiOperation(value = "频道展示", notes = "author:liJie")  // value指名称  notes 备注
    @ApiImplicitParam(name = "", value = "频道展示无参数", required = true, dataType = "")
    public ResponseResult list(){
        List<WmChannel> list = iWmChannelService.list();
        return ResponseResult.okResult(list);
    }


}
